// review-address
import { DELIVERY_TYPE_ENUM, DELIVERY_TYPE_TEXT } from '../../../../constants/order';
const componentBehaviors = require('../../../../behaviors/component');
import { COMPONENT_OPTIONS } from '../../../../constants/common';

Component({
    behaviors: [componentBehaviors],
    options: {
        ...COMPONENT_OPTIONS,
    },
    /**
     * 组件的属性列表
     */
    properties: {
        // 支持的配送方式
        supportType: {
            type: Array,
            value: [],
        },
        expressType: {
            type: String,
            value: '',
        },
        // 地址信息
        addressInfo: {
            type: Object,
            value: {},
        },
        // 自提点信息
        siteInfo: {
            type: Object,
            value: {},
        },
        // 时间信息
        timeInfo: {
            type: Object,
            value: {},
        },
    },

    lifetimes: {
        attached: function() {
          // 在组件实例进入页面节点树时执行
          const typeList = this.data.supportType;
          if (typeList.length > 0 && typeList.indexOf(DELIVERY_TYPE_ENUM.none) === -1) {
              this.onChangeType(typeList[0]);
          }
        },
    },
    /**
     * 组件的初始数据
     */
    data: {
        typeEnum: DELIVERY_TYPE_ENUM,
        typeText: DELIVERY_TYPE_TEXT,
        showSelectType: false,
    },

    /**
     * 组件的方法列表
     */
    methods: {
        changeTypeAction: function (event) {
            this.onChangeType(event.currentTarget.dataset.value);
        },
        closeChangeType: function () {
            this.setData({
                showSelectType: false,
            });
        },
        showChangeType: function () {
            this.setData({
                showSelectType: true,
            });
        },
        // 修改配送方式
        onChangeType: function (type) {
            console.log('ReviewAddress => 修改配送方式', type);
            this.closeChangeType();
            this.triggerEvent('changeType', type);
        },
        // 选择、修改地址
        addressAction: function () {
            console.log('ReviewAddress => 修改地址');
            this.triggerEvent('changeAddress');
        },
        // 选择、修改自提点
        siteAction: function () {
            // console.log('ReviewAddress => 修改自提点');
            // this.triggerEvent('changeSite');
        },
        // 自提时间
        timeAction: function () {
            console.log('ReviewAddress => 修改自提时间');
            this.triggerEvent('changeTime');
        },
    }
})
